.TH std::experimental::source_location 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::experimental::source_location \- std::experimental::source_location

.SH Synopsis
   Defined in header <experimental/source_location>
   struct source_location;                           (library fundamentals TS v2)

   The source_location class represents certain information about the source code, such
   as file names, line numbers, and function names. Previously, functions that desire
   to obtain this information about the call site (for logging, testing, or debugging
   purposes) must use macros so that predefined macros like __LINE__ and __FILE__ are
   expanded in the context of the caller. The source_location class provides a better
   alternative.

.SH Member functions

         Creation
                         constructs a new source_location with implementation-defined
   constructor           values
                         \fI(public member function)\fP
   current               constructs a new source_location
   \fB[static]\fP              \fI(public static member function)\fP
         Other special member functions
   destructor            destructs a source_location
   (implicitly declared) \fI(public member function)\fP
   operator=             implicitly declared copy/move assignment operators
   (implicitly declared) \fI(public member function)\fP
         Field access
   line                  return the line number represented by this object
                         \fI(public member function)\fP
   column                return the column number represented by this object
                         \fI(public member function)\fP
   file_name             return the file name represented by this object
                         \fI(public member function)\fP
                         return the name of the function represented by this object, if
   function_name         any
                         \fI(public member function)\fP

.SH Example


// Run this code

 #include <experimental/source_location>
 #include <iostream>
 #include <string_view>

 void log(const std::string_view message,
          const std::experimental::source_location location =
                std::experimental::source_location::current())
 {
     std::cout << "info:"
               << location.file_name() << ':'
               << location.line() << ' '
               << message << '\\n';
 }

 int main()
 {
     log("Hello world!");
 }

.SH Possible output:

 info:main.cpp:15 Hello world!
